package com.freestyle.jmssample.rabbitmq;

import com.freestyle.jmssample.api.JMSDeclare;
import com.freestyle.jmssample.api.SMSConstants;
import com.freestyle.jmssample.api.SendSMSService;
import com.freestyle.jmssample.api.pojo.JSONData;
import com.freestyle.jmssample.api.pojo.SMSBean;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * Created by rocklee on 2022/1/7 15:51
 */
@Configuration
public class AppEvent implements ApplicationListener<ApplicationReadyEvent> {
  @Resource
  private SendSMSService sendSMSService;
  @Resource
  private JMSDeclare jmsDeclare;
  @Override
  public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
    //if (1+1==2)return;
    jmsDeclare.clearQueueData(SMSConstants.SMS_QUEUE_DIRECT);
    jmsDeclare.clearQueueData(SMSConstants.SMS_QUEUE_DIRECT2);
    jmsDeclare.clearQueueData(SMSConstants.SMS_QUEUE_DIRECT3);
    //sendSMSService.sendSMSWithACK(sms,"xxxqueue");
    //投到SMS_KEY_DIRECT中，onReceived/onReceived2接收,发送方有confirm回调
    //sendSMSService.sendSMSWithACK(sms,SMSConstants.SMS_KEY_DIRECT);


    /*sms.setContent("此消息需要consumer回应...");
    JSONData<String> ret= null;
    try {
      ret = sendSMSService.sendSMSandReceive(sms);
      System.out.println(ret);
    } catch (Exception e) {
      System.out.println("操作失败："+e.getMessage());
    }*/

  }
}
